<?php
$activities = $list;
$btn = array(
    'name' => 'subscribe',
    'id' => 'subscribe',
    'value' => 'Subscribe',
    'class' => 'blockForm btn'
);
$btnD = array(
    'name' => 'subscribe',
    'id' => 'subscribe',
    'value' => 'Unsubscribe',
    'class' => 'blockForm btn'
);

$btn_delete = array(
    'name' => 'delete',
    'id' => 'delete',
    'content' => 'Delete',
    'class' => 'blockForm btn'
);
$btn_edit = array(
    'name' => 'edit',
    'id' => 'edit',
    'content' => 'Edit',
    'class' => 'blockForm btn',
    'type' => 'submit'
);
?>
<div id="show-list" class="ui-widget">
    <div class=" ui-widget-header ui-corner-all ui-helper-clearfix pushDown tCenter titulo">
        <span class="ui-dialog-title">ACTIVITIES</span>
    </div>
    <table id="activity" class="ui-widget ui-widget-content">
        <thead>
            <tr class="ui-widget-header ">
                <th>Name</th>
                <th>Date</th>
                <th>Price</th>
                <th>Description</th>
                <th>Place</th>
                <?php if ($user_type == 2) { ?><th></th> <?php } ?>

                <?php if ($user_type == 1) { ?><th colspan="2" ></th> <?php } ?>

            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($activities as $ac) {
                $date_hoy = new DateTime();
                $date_ac = new DateTime($ac['date_act']);
                ?>
                <tr>
                    <td><?= $ac['name'] ?></td>
                    <td><?= $ac['fecha'] ?></td>
                    <td><?= $ac['price'] ?></td>
                    <td><?= $ac['description'] ?></td>
                    <td><?= $ac['placement'] ?></td>
                    <?php if ($user_type == 2) { ?>

                        <td class="tCenter">  

                            <?php
                            $action = 'userControl/subscribe';
                            $bt = $btn;
                            foreach ($ua as $a) {
                                if ($a['id_activity'] == $ac['id']) {
                                    $bt = $btnD;
                                    $action = 'userControl/unsubscribe';
                                }
                            }
                            if ($date_hoy < $date_ac) {
                                ?>


                                <?= form_open($action); ?>
                                <?= form_hidden('id_activity', $ac['id']); ?>
                                <?= form_submit($bt); ?>
                                <?= form_close(); ?>
                            <?php } ?>
                        </td>
                    <?php } ?>
                    <?php if ($user_type == 1) { // ************************************** Admin Controls ?> 
                        <td class="tCenter">  
                            <?php
                            $action = 'activity/delete/' . $ac['id'];
                            $bt = $btn_delete;
                            $bt['onclick'] = 'confirmDialog(' . $ac['id'] . ')';
                            ?>

                            <?= form_open($action, array("id" => "form_delete_" . $ac['id'])); ?>
                            <?= form_hidden('id_activity', $ac['id']); ?>
                            <?= form_button($bt); ?>
                            <?= form_close(); ?>

                        </td>
                        <td class="tCenter">   
                            <?php
                            $action = 'activity/add/' . $ac['id'];
                            $bt = $btn_edit;
                            ?>

                            <?= form_open($action); ?>
                            <?= form_hidden('id_activity', $ac['id']); ?>
                            <?= form_button($bt); ?>
                            <?= form_close(); ?>

                        </td>
                    <?php } ?>

                </tr>
            <?php } ?>
        </tbody>
    </table>

    <?= $pager ?>

</div>

<div id="dialog-confirm" style=" display: none; font-size: 13px" title="Are you sure, do you want to delete this activity?">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>

<script type="text/javascript">
    function confirmDialog(id) {

        $("#dialog-confirm").dialog({
            resizable: false,
            height: 200,
            modal: true,
            width: 550,
            buttons: {
                "Delete Activity": function() {
                    $("#form_delete_" + id).submit();
                    $(this).dialog("close");
                },
                Cancel: function() {
                    $(this).dialog("close");
                }
            }
        });
    }

    function edit(){
    
    }

    $(document).ready(function() {
        $('.btn').button().css({'font-size': '14px'});


    });

</script>

